package org.alis.smallcc.designpatterns.behavior.chain;

import java.util.Objects;

/**
 * 
 *  责任连模式 
 * @author: luochuan     
 * @date: 2020年10月30日 下午4:26:05   
 */
public abstract class AbstractChainHandler {
	protected AbstractChainHandler nextHandler;
	
	public final AbstractChainHandler setNextHandler(AbstractChainHandler nextHandler) {
		this.nextHandler = nextHandler;
		return this;
	}
	
	public final boolean next(UserRequest request) {
		if(isNeedNext(request)&&Objects.nonNull(nextHandler)) {
			System.out.println(String.format("用户:%s 借的钱:%d 借钱的次数:%d 不符合当前%s审理,已经提交给%s处理了",request.getUserName(),request.getAmount(),request.getCount(),this.getClass().getName(),nextHandler.getClass().getName()));
			return this.nextHandler.next(request);
		}
		return !isNeedNext(request);
	} 
	
	
	public abstract boolean defaultNext(UserRequest request);
	
	
	protected abstract boolean isNeedNext(UserRequest request);
}
